home *** CD-ROM | disk | FTP | other *** search
/ PC Basics 53 / PC Basics Issue 53.iso / Software / Internet / Invboard.exe / PC Basics 53 / Invboard / upload / sources / Online.php < prev    next >
Encoding:
PHP Script  |  2002-06-12  |  7.4 KB  |  282 lines

  1. <?php
  2.  
  3. /*
  4. +--------------------------------------------------------------------------
  5. |   IBFORUMS v1
  6. |   ========================================
  7. |   by Matthew Mecham and David Baxter
  8. |   (c) 2001,2002 IBForums
  9. |   http://www.ibforums.com
  10. |   ========================================
  11. |   Web: http://www.ibforums.com
  12. |   Email: phpboards@ibforums.com
  13. |   Licence Info: phpib-licence@ibforums.com
  14. +---------------------------------------------------------------------------
  15. |
  16. |   > Show online users
  17. |   > Module written by Matt Mecham
  18. |   > Date started: 12th March 2002
  19. |
  20. |    > Module Version Number: 1.0.0
  21. +--------------------------------------------------------------------------
  22. */
  23.  
  24.  
  25. $idx = new Online;
  26.  
  27. class Online {
  28.  
  29.     var $output     = "";
  30.     var $page_title = "";
  31.     var $nav        = array();
  32.     var $html       = "";
  33.     var $first      = 0;
  34.     var $perpage    = 25;
  35.     
  36.     var $forums     = array();
  37.     var $cats       = array();
  38.     var $sessions   = array();
  39.     var $where      = array();
  40.     
  41.     var $seen_name  = array();
  42.     
  43.     
  44.     
  45.     function Online() {
  46.         global $ibforums, $DB, $std, $print;
  47.         
  48.         
  49.         if ($ibforums->input['CODE'] == "") $ibforums->input['CODE'] = 'listall';
  50.         
  51.         //--------------------------------------------
  52.         // Require the HTML and language modules
  53.         //--------------------------------------------
  54.         
  55.         $ibforums->lang = $std->load_words($ibforums->lang, 'lang_online', $ibforums->lang_id);
  56.         
  57.         require "./Skin/".$ibforums->skin_id."/skin_online.php";
  58.         
  59.         $this->html = new skin_online();
  60.         
  61.         $this->base_url        = "{$ibforums->vars['board_url']}/index.{$ibforums->vars['php_ext']}?s={$ibforums->session_id}";
  62.         
  63.         //--------------------------------------------
  64.         // Build up our language hash
  65.         //--------------------------------------------
  66.         
  67.         foreach ($ibforums->lang as $k => $v) {
  68.             if ( preg_match( "/^WHERE_(\w+)$/", $k, $match ) ) {
  69.                 $this->where[ $match[1] ] = $ibforums->lang[$k];
  70.             }
  71.         }
  72.         
  73.         unset($match);
  74.         
  75.         //--------------------------------------------
  76.         // What to do?
  77.         //--------------------------------------------
  78.         
  79.         switch($ibforums->input['CODE']) {
  80.             case 'listall':
  81.                 $this->list_all();
  82.                 break;
  83.             case '02':
  84.                 $this->list_forum();
  85.                 break;
  86.             default:
  87.                 $this->list_all();
  88.                 break;
  89.         }
  90.         
  91.         // If we have any HTML to print, do so...
  92.         
  93.         $print->add_output("$this->output");
  94.         $print->do_output( array( 'TITLE' => $this->page_title, 'JS' => 0, NAV => $this->nav ) );
  95.             
  96.      }
  97.      
  98.      
  99.     /*****************************************************/
  100.     // list_all
  101.     // ------------------
  102.     // List all online users
  103.     /*****************************************************/
  104.     
  105.     function list_all() {
  106.         global $ibforums, $DB, $std;
  107.         
  108.         $this->first = 0;
  109.         
  110.         if (!empty($ibforums->input['st']))
  111.         {
  112.             $this->first = $ibforums->input['st'];
  113.         }
  114.         
  115.         $last_cat_id = -1;
  116.         
  117.         $DB->query("SELECT f.id, f.name, f.read_perms, f.password, c.id as cat_id, c.name as cat_name from ibf_forums f, ibf_categories c where c.id=f.category ORDER BY c.position, f.position");
  118.         
  119.         
  120.         while ( $i = $DB->fetch_row() )
  121.         {
  122.             if ($last_cat_id != $i['cat_id'])
  123.             {
  124.                 // Print the category
  125.                 
  126.                 $last_cat_id = $i['cat_id'];
  127.                 
  128.                 $this->cats[ $i['cat_id'] ] = $this->cats['cat_name'];
  129.                 
  130.             }
  131.             
  132.             $this->forums[ $i['id'] ] = array( 'name'         => $i['name'],
  133.                                                'read_perms'   => $i['read_perms'],
  134.                                                'password'      => $i['password'],
  135.                                              );
  136.             
  137.         }
  138.         
  139.         $DB->free_result();
  140.         
  141.         $t_time = time() - 900;
  142.         
  143.         $DB->query("SELECT COUNT(id) as total_sessions FROM ibf_sessions WHERE login_type <> 1 AND running_time > $t_time");
  144.         $max = $DB->fetch_row();
  145.         
  146.         $DB->free_result();
  147.         
  148.         $links = $std->build_pagelinks(  array( 'TOTAL_POSS'  => $max['total_sessions'],
  149.                                                 'PER_PAGE'    => 25,
  150.                                                 'CUR_ST_VAL'  => $this->first,
  151.                                                 'L_SINGLE'     => "",
  152.                                                 'L_MULTI'      => $ibforums->lang['pages'],
  153.                                                 'BASE_URL'     => $this->base_url."&act=Online&CODE=listall"
  154.                                               )
  155.                                        );
  156.                                        
  157.         $this->output = $this->html->Page_header($links);
  158.         
  159.         // Grab all the current sessions.
  160.         
  161.         $DB->query("SELECT s.id, s.member_name, s.member_id, s.running_time, s.location, s.member_group, g.prefix, g.suffix FROM ibf_sessions s, ibf_groups g WHERE login_type <> 1 AND running_time > $t_time AND s.member_group=g.g_id ORDER BY running_time DESC LIMIT ".$this->first.",25");
  162.         
  163.         while( $sess = $DB->fetch_row() ) {
  164.         
  165.             //----------------------------------------------------
  166.             // Is this a member, and have we seen them before?
  167.             // Proxy servers, etc can confuse the session handler,
  168.             // creating duplicate session IDs for the same user when
  169.             // their IP address changes.
  170.             //----------------------------------------------------
  171.             
  172.             if (! empty($sess['member_name']) )
  173.             {
  174.                 if (isset($this->seen_name[ $sess['member_name'] ]) )
  175.                 {
  176.                     continue;
  177.                 }
  178.                 else
  179.                 {
  180.                     $this->seen_name[ $sess['member_name'] ] = 1;
  181.                 }
  182.             }
  183.             
  184.             if (isset($sess['location']))
  185.             {
  186.             
  187.                 $line = "";
  188.                 
  189.                 list($act, $fid, $tid, $pid) = explode( ",", $sess['location'] );
  190.                 
  191.                 if (isset($act))
  192.                 {
  193.                     $line = isset($this->where[ $act ]) ? $this->where[ $act ] : $ibforums->lang['board_index'];
  194.                 
  195.                 }
  196.                 
  197.                 
  198.                 if ($fid != "")
  199.                 {
  200.                     $pass = 0;
  201.                     
  202.                     if ($this->forums[ $fid ]['read_perms'] == '*')
  203.                     {
  204.                         $pass = 1;
  205.                     }
  206.                     else if (preg_match( "/(^|,)".$ibforums->member['mgroup']."(,|$)/", $this->forums[ $fid ]['read_perms']) )
  207.                     {
  208.                         $pass = 1;
  209.                     }
  210.                     
  211.                     if ($pass == 1)
  212.                     {
  213.                         if ($tid != "")
  214.                         {
  215.                             $line .= " <a href='{$this->base_url}&act=ST&f=$fid&t=$tid'>{$this->forums[ $fid ]['name']}</a>";
  216.                         }
  217.                         else
  218.                         {
  219.                             $line .= " <a href='{$this->base_url}&act=SF&f=$fid'>{$this->forums[ $fid ]['name']}</a>";
  220.                         }
  221.                     }
  222.                     else
  223.                     {
  224.                         $line .= " ".$ibforums->lang['n_a'];
  225.                     }
  226.                 }
  227.                  
  228.             }
  229.             else
  230.             {
  231.                 $line .= " <a href='{$this->base_url}'>{$ibforums->lang['board_index']}</a>";
  232.             }
  233.             
  234.             
  235.             $sess['where_line'] = $line;
  236.             
  237.             if (isset($sess['member_id']))
  238.             {
  239.                 $sess['member_name'] = "<a href='{$this->base_url}&act=Profile&CODE=03&MID={$sess['member_id']}'>{$sess['prefix']}{$sess['member_name']}{$sess['suffix']}</a>";
  240.             }
  241.             
  242.             $sess['running_time'] = $std->get_date( $sess['running_time'], 'LONG' );
  243.             
  244.             $this->output .= $this->do_html_row($sess);
  245.             
  246.         }
  247.         
  248.         $this->output .= $this->html->Page_end($links);
  249.         
  250.         $this->page_title = $ibforums->lang['page_title'];
  251.         $this->nav        = array( $ibforums->lang['page_title']);
  252.                 
  253.     }
  254.     
  255.     function do_html_row($sess) {
  256.         global $ibforums;
  257.         
  258.         if ($sess['member_name'] and $sess['member_id'])
  259.         {
  260.             $sess['msg_icon']     = "<a href='{$this->base_url}&act=Msg&CODE=04&MID={$sess['member_id']}'>{$ibforums->skin['P_MSG']}</a>";
  261.         }
  262.         else
  263.         {
  264.             $sess['member_name']  = $sess['prefix'].$ibforums->lang['guest'].$sess['suffix'];
  265.             $sess['msg_icon']     = ' ';
  266.         }
  267.         
  268.         return $this->html->show_row($sess);
  269.     }
  270.     
  271.     
  272.     function list_forum() { }
  273.     
  274.             
  275.     
  276.  
  277.  
  278.         
  279. }
  280.  
  281. ?>
  282.